﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XNA_TD
{
    class TimedRegister : IRunable, IFixedGameUpdate
    {
        private List<IRunable> toRegister;
        private int msToGo;
        private double endTime;

        public TimedRegister(IRunable runable, int ms)
            : base(Priority.Logic)
        {
            toRegister = new List<IRunable>(1);
            toRegister.Add(runable);
            msToGo = ms;
        }

        public TimedRegister(List<IRunable> runable, int ms)
            : base(Priority.Logic)
        {
            toRegister = runable;
            msToGo = ms;
        }

        public void FixedGameUpdate()
        {
            if (endTime <= inGameTime)
            {
                UnRegister(this);
                foreach (var runable in toRegister)
                {
                    Register(runable);
                }
            }
        }

        public override void Load()
        {
            endTime = msToGo + inGameTime;
        }

        public override void UnLoad()
        {
        }
    }
}
